package com.quickpass.order.service;

import com.quickpass.order.config.RedissonConfig;
import com.quickpass.order.domain.ShopCart;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: 弔人
 * @time: 2023/2/6 9:57
 */
@Service
public class ShopCartService {

    @Autowired
    private RedisTemplate redisTemplate;



    public AjaxResult adt(ShopCart shopCart) {
        ShopCart cart = (ShopCart) redisTemplate.opsForHash().get("shopCart:"+shopCart.getMemberid(), shopCart.getId().toString());
        if (cart!=null){
            shopCart.setNumber(shopCart.getNumber()+cart.getNumber());
        }
        redisTemplate.opsForHash().put("shopCart:"+shopCart.getMemberid(), shopCart.getId().toString(), shopCart);


        return new AjaxResult(1, "加入购物车");
    }

    public List<ShopCart> getShost(Long userId) {
        //List<SkuInfoDTO> cartList = redisTemplate.opsForHash().values("cartList:" + userId);
        List<ShopCart> shopCartList = (List<ShopCart>) redisTemplate.opsForHash().values("shopCart:"+userId);
        System.out.println(redisTemplate.opsForHash().get("shopCart:", "member"+userId));
        return shopCartList;
    }
}
